package com.xiaodou.mjf.infrastructure.common.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.xiaodou.mjf.infrastructure.common.utils.CodeGenerator;
import com.xiaodou.mjf.infrastructure.common.utils.StringUtils;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.Transient;

@MappedSuperclass
public class IdEntity extends CommonEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = -2672840337758355791L;
	@Id
	protected String id;

    @Transient
    @JsonIgnore
    protected Integer start;
    @Transient
    @JsonIgnore
    protected Integer limit;
    @Transient
    @JsonIgnore
    protected Integer page = 1;

	@PrePersist
	public void prePersist(){
		if(StringUtils.isBlank(this.id)) {
            this.id = CodeGenerator.UUID();
        }
	}
	
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}
	
    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

	public final static String SORT = "sort";
	
}
